package test;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: caporegim
 * Date: 08.09.12
 * Time: 11:31
 * To change this template use File | Settings | File Templates.
 */
public class Sort {
    public static final int SIZE = 10000000;
    public static void main(String[] args) {

        List list = new ArrayList(SIZE);
        fill(SIZE, list);
        timeCheck(list);
        sort(list);
        timeCheck2(list);
        int n = 1;
        n += 1;
        n /= 1;

        int n  += n 2;
    }

    private static void timeCheck(List list) {
        long start = System.currentTimeMillis();
        long countTimes = 0;
        for(int i = SIZE - 1000; i < SIZE; i++) {
            if(list.contains(i)){
               countTimes++;
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("list contains time to check " + (end - start) + " ms");
    }
    private static void timeCheck2(List list) {
        long start = System.currentTimeMillis();
        long countTimes = 0;
        for(int i = SIZE - 1000; i < SIZE; i++) {
            int res = Collections.binarySearch(list, new Integer(i));

        }
        long end = System.currentTimeMillis();
        System.out.println("list contains time to check " + (end - start) + " ms");
    }

    private static void sort(List list) {
        Collections.sort(list);
    }

    private static void fill(int size, List list) {
        Random random = new Random();
        for(int i = 1; i < size; i++) {
            list.add(i);
        }
        //Collections.shuffle(list);
    }
}
